package com.xbongbong.saas.model;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.IModel;
import com.xbongbong.saas.domain.entity.ContactUserEntity;
import com.xbongbong.saas.domain.entity.UserTeamEntity;
import org.elasticsearch.action.support.WriteRequest;

import java.util.List;
import java.util.Map;

/**
 * @author feng.zheng
 * @version v1.0
 * @date 2019/1/24 15:44
 * @since v1.0
 */

public interface ContactUserModel extends IModel<ContactUserEntity> {

    /**
     * 保存实体
     *
     * @param contactUserEntity 联系人协同人团队实体
     * @return java.lang.Integer
     * @throws XbbException 数据库异常
     * @author feng.zheng
     * @date 2019/2/14 16:42
     */
    Integer save(ContactUserEntity contactUserEntity) throws XbbException;

    /**
     * 获取单个实体
     *
     * @param key    id主键
     * @param corpid 公司id
     * @return com.xbongbong.saas.domain.entity.ContactUserEntity
     * @author feng.zheng
     * @date 2019/2/14 16:43
     */
    ContactUserEntity getByKey(Long key, String corpid);

    /**
     * 批量删除
     *
     * @param list 更新的数据id
     * @param corpid                公司id
     * @return 是否成功
     * @throws XbbException 异常
     */
    Integer deleteBatch(List<Long> list, String corpid) throws XbbException;

    /**
     * 批量删除
     * @param corpid
     * @param list
     * @param refreshPolicy
     * @param del
     */
    void deleteBatch(String corpid, List<ContactUserEntity> list, WriteRequest.RefreshPolicy refreshPolicy, Integer del) throws XbbException;

    /**
     * 根据联系人id删掉该联系人的协同团队
     *
     * @param customerId 联系人关联客户id
     * @param contactId  联系人id
     * @param corpid     公司id
     * @return 是否成功
     * @throws XbbException 异常
     */
    Integer deleteBatchByCustomerAndContact(Long customerId, Long contactId, String corpid) throws XbbException;

    /**
     * 批量解散团队依据客户id
     * @param corpid
     * @param customerIdIn
     */
    void disbandedTeamByCustomerId(String corpid, List<Long> customerIdIn) throws XbbException;
    /**
     * 获取符合查询条件的记录
     *
     * @param param 查询条件
     * @return 符合查询条件的记录
     */
    @Override
    List<ContactUserEntity> findEntitys(Map<String, Object> param);

    /**
     * 根据联系人id批量删除
     * @param contactIdIn 联系人id
     * @param corpid 公司id
     * @return
     */
    Integer deleteBatchByContactIdIn(List<Long> contactIdIn, String corpid) throws XbbException;

    /**
     * 根据客户id和userId删除联系人团队
     *
     * @param corpid
     * @param customerId
     * @param userId
     * @author feng.zheng
     * @return java.lang.Integer
     * @date 2019/3/10 15:13
     */
    Integer deleteByUserIdAndCustomerId(String corpid, Long customerId, String userId) throws XbbException;

    List<UserTeamEntity> findBaseEntitys(Map<String,Object> map);

    void insertBatch(List<ContactUserEntity> contactUserEntityList, boolean isImport) throws XbbException;

    void batchUpdateByUserIdIn(String corpid, List<Long> dataIdIn, List<UserTeamEntity> teamEntityList, Integer isMain, Integer del) throws XbbException;

    void batchUpdateByUserIdIn(String corpid, List<Long> dataIdIn, List<UserTeamEntity> teamEntityList, Integer isMain, Integer del, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    void deleteBatchUser(List<ContactUserEntity> contactUserEntityList, String corpid) throws XbbException;

    /**
     * 获取该客户的所有相关联系人
     * @param corpid
     * @param contactId
     * @return java.util.List<com.xbongbong.saas.domain.entity.ContactUserEntity>
     * @author 吴峰
     * @date 2021/9/16 10:52
     */
    List<ContactUserEntity> getUserListByContactId(String corpid, Long contactId, Integer del);


    /**
     * 获取该客户的所有相关联系人
     * @param corpid
     * @param customerId
     * @return java.util.List<com.xbongbong.saas.domain.entity.ContactUserEntity>
     * @author 石安
     * @date 2019-09-23
     */
    List<ContactUserEntity> getListByCustomerId(String corpid, Long customerId);

    List<ContactUserEntity> getListByContactId(String corpid, Long contactId, Integer isMain);

    /**
     * 获取原始数据，不需要去重
     * @param params
     * @return
     */
    List<ContactUserEntity> findEntityOriginal(Map<String, Object> params);

    /**
     * 批量编辑
     * @param list
     * @param corpid
     * @return
     * @throws XbbException
     */
    Integer updateBatch(List<ContactUserEntity> list, String corpid) throws XbbException;

    /**
     * 编辑团队成员标签
     *
     * @param contactUserEntity
     */
    void editLabel(ContactUserEntity contactUserEntity) throws XbbException;

    /**
     * 更新协同人可编辑权限
     *
     * @param shouldUpdateEntity
     */
    void updateEditFormPer(ContactUserEntity shouldUpdateEntity) throws XbbException;

    /**
     * 更新团队协同人信息和协同人可编辑权限
     *
     * @param corpid
     * @param idIn
     * @param updateUserToCoTeamList
     * @param coopUser
     * @param needThrow
     */
    void batchUpdateCoAndPerByUserIdIn(String corpid, List<Long> idIn, List<UserTeamEntity> updateUserToCoTeamList, Integer coopUser, boolean needThrow) throws XbbException;

    void batchUpdateCoAndPerByUserIdIn(String corpid, List<Long> idIn, List<UserTeamEntity> teamEntityList, Integer isMain, boolean needThrow, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    /**
     * 批量解散团队依据dataId
     * @param corpid
     * @param dataIdList
     */
    void disbandedTeamByDataId(String corpid, List<Long> dataIdList) throws XbbException;

}


